package com.gaomall.seckill.utils;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.gaomall.seckill.enums.ResponseStatusCode;
import com.gaomall.seckill.vo.ResultVO;

public class ResultVOUtil<T>{

//    /** 错误码. 如：200*/
//    private Integer return_code;
//
//    /** 请求状态. 参数：SUCCESS、 FAIL*/
//    private String result_code;
//
//    /** 提示信息. 如：成功*/
//    private String return_msg;
//
//    /** 具体内容. */
//    private T data;

    //使之不在json序列化结果当中
//    @JsonIgnore
//    public static boolean isSuccess(){
//        return 200 == ResponseStatusCode.SUCCESS.getReturn_code();
//    }

    /**
     * 成功 默认参数
     * @return
     */
    public static ResultVO success() {
        ResultVO resultVO = new ResultVO();
        resultVO.setResult_code(ResponseStatusCode.SUCCESS.getReturn_msg());
        resultVO.setReturn_code(ResponseStatusCode.SUCCESS.getReturn_code());
        resultVO.setReturn_msg(ResponseStatusCode.SUCCESS.getReturn_msg());
        return resultVO;
    }

    /**
     * 成功 消息参数
     * @return
     */
    public static ResultVO success(String msg) {
        ResultVO resultVO = new ResultVO();
        resultVO.setResult_code(ResponseStatusCode.SUCCESS.getReturn_msg());
        resultVO.setReturn_code(ResponseStatusCode.SUCCESS.getReturn_code());
        resultVO.setReturn_msg(msg);
        return resultVO;
    }

//    public static ResultVO success(T data)

    /**
     * 成功 数据参数
     * @return
     */
    public static ResultVO success(Object data) {
        ResultVO resultVO = new ResultVO();
        resultVO.setData(data);
        resultVO.setResult_code(ResponseStatusCode.SUCCESS.getReturn_msg());
        resultVO.setReturn_code(ResponseStatusCode.SUCCESS.getReturn_code());
        resultVO.setReturn_msg(ResponseStatusCode.SUCCESS.getReturn_msg());
        return resultVO;
    }

    /**
     * 成功 消息和数据参数
     * @return
     */
    public static ResultVO success(String msg, Object data) {
        ResultVO resultVO = new ResultVO();
        resultVO.setResult_code(ResponseStatusCode.SUCCESS.getReturn_msg());
        resultVO.setReturn_code(ResponseStatusCode.SUCCESS.getReturn_code());
        resultVO.setReturn_msg(msg);
        resultVO.setData(data);
        return resultVO;
    }

    /**
     * 失败 默认参数
     * @return
     */
    public static ResultVO error() {
        ResultVO resultVO = new ResultVO();
        resultVO.setResult_code(ResponseStatusCode.ERROR.getReturn_msg());
        resultVO.setReturn_code(ResponseStatusCode.ERROR.getReturn_code());
        resultVO.setReturn_msg(ResponseStatusCode.ERROR.getReturn_msg());
        return resultVO;
    }

    /**
     * 失败 消息参数
     * @return
     */
    public static ResultVO error(String msg) {
        ResultVO resultVO = new ResultVO();
        resultVO.setResult_code(ResponseStatusCode.ERROR.getReturn_msg());
        resultVO.setReturn_code(ResponseStatusCode.ERROR.getReturn_code());
        resultVO.setReturn_msg(msg);
        return resultVO;
    }

    /**
     * 失败 错误码和消息参数
     * @return
     */
    public static ResultVO error(Integer code, String msg) {
        ResultVO resultVO = new ResultVO();
        resultVO.setResult_code(ResponseStatusCode.ERROR.getReturn_msg());
        resultVO.setReturn_code(code);
        resultVO.setReturn_msg(msg);
        return resultVO;
    }

}
